<?php
namespace My\Controller;

use Utuo\BackgroundController;
use Utuo\Region;

class InformationController extends BackgroundController {
	
	public function _initialize() {
		$this->setControllerTitle("信息设置");
		$this->setActionTitle(array(
				'index' => '编辑信息',
		));
	}
	
	// 信息编辑
	public function indexAction() {
		$d = D("Customer");
		$customer = $d->find($this->aid);
		$this->assign("provinceOptions", $this->getOption(Region::getProvinceList(), $customer['province'], '==请选择省份=='));
		$this->assign("cityOptions", $this->getOption(Region::getCityListByProvince($customer['province']), $customer['city'], '==请选择城市=='));
		$this->assign("areaOptions", $this->getOption(Region::getAreaListByCity($customer['city']), $customer['area'], '==请选择地区=='));
		$this->assign("customer",$customer);
		$this->display();
	}
	
	// 提交信息
	public function indexPostAction() {
		$d = D("Customer");
		if ( $d->create() ) {
			$d->id = $this->aid;
			if (false !== $d->save()) {
				$this->ajaxSuccess();
			} else {
				$this->ajaxError($d->getError());
			}
		} else {
			$this->ajaxError($d->getError());
		}
	}
	
	// 获取城市
	public function getCityPostAction() {
		echo $this->getOption(Region::getCityListByProvince(I('code')), '', '==请选择城市==');
	}
	
	// 获取地区
	public function getAreaPostAction() {
		echo $this->getOption(Region::getAreaListByCity(I('code')), '', '==请选择地区==');
	}
	
}